import {
    requestToken,
    requestUserName,
    requestLogOut
} from "@/api/token"

export const actions = {
    async getToken({
        commit
    }, userInfo) {
        const result = await requestToken(userInfo)
        commit("SET_TOKEN", result.token)
        //数据持久化
        localStorage.setItem('user_Token',result.token)
    },
    async getUserName({
        commit
    }) {
        const result = await requestUserName()
        commit("SET_USERNAME", result.name)
    },
    async getLogOut({
        commit
    }) {
        await requestLogOut()
        commit("SET_TOKEN", '')
        commit("SET_USERNAME", '')
        localStorage.removeItem("user_Token")
    },

}